package com.orangelife.mobile.parkingcard.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.curry.android.util.IntentHelper;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.parkingcard.activity.ApplyForParkingCardBeginActivity;
import com.orangelife.mobile.parkingcard.activity.ParkingAuthenticationActivity;
import com.orangelife.mobile.parkingcard.bean.ParkingInfomation;

import butterknife.ButterKnife;

/**
 * Created by yyx
 * on 2015/11/17.
 */
public class NoDataFragment extends Fragment implements View.OnClickListener{

    /**叹号下面的提示*/
    private TextView tvTip;
    /**按钮*/
    private Button btnSubmit;
    /**橙色的提示*/
    private TextView tvTip2;
    private View view;
    /**1表示私有，2表示公共*/
    private int type;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_parking_nodata,
                    null);
        }
        initeView();
        findView();
		/*
         * 缓存的rootView需要判断是否已经被加过parent，
		 * 如果有parent需要从parent删除，要不然会发生这个view已经有parent的错误。
		 */
        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
        ButterKnife.bind(this, view);
        return view;
    }

    /**
     * 初始化
     */
    private void initeView() {
        tvTip = (TextView) view.findViewById(R.id.tvTip);
        tvTip2 = (TextView) view.findViewById(R.id.tvTip2);
        btnSubmit = (Button) view.findViewById(R.id.btnSubmit);
    }

    /**
     * 初始化赋值
     */
    private void findView() {
         type = ParkingInfomation.getType();
        if (type == 2){
            tvTip.setText(R.string.no_data_tip3);
            tvTip2.setVisibility(View.GONE);
            btnSubmit.setText("添加停车卡");
        }
        btnSubmit.setOnClickListener(this);
    }

    /**
     * 更新UI
     */
    public void updateUI(){
        type = ParkingInfomation.getType();
        if (type == 2){
            tvTip.setText(R.string.no_data_tip3);
            tvTip2.setVisibility(View.GONE);
            btnSubmit.setText("添加停车卡");
        }else if(type == 1){
            tvTip.setText(R.string.no_data_tip);
            tvTip2.setVisibility(View.VISIBLE);
            btnSubmit.setText("立即绑定");
        }
        btnSubmit.setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btnSubmit:
                if(type == 1){
                    IntentHelper.getInstances().getIntent(getActivity(), ParkingAuthenticationActivity.class);
                }else if(type == 2){
                    IntentHelper.getInstances().getIntent(getActivity(), ApplyForParkingCardBeginActivity.class);
                }
                break;
        }
    }
}
